package com.ldc.security;

import com.ldc.common.constants.ConstantsCodeStatus;
import com.ldc.common.utils.ResponseUtils;
import com.ldc.model.utils.ResultUtils;
import org.springframework.security.web.session.SessionInformationExpiredEvent;
import org.springframework.security.web.session.SessionInformationExpiredStrategy;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import java.io.IOException;

/**
 * 自定义异地登录、账号下线时的逻辑处理
 *
 * @auther liudc
 * @since 2022/11/6
 */
@Component
public class CustomSessionInformationExpiredStrategy implements SessionInformationExpiredStrategy {
    @Override
    public void onExpiredSessionDetected(SessionInformationExpiredEvent event) throws IOException, ServletException {
        ResponseUtils.toResult(event.getResponse(), ResultUtils.toFailed("您账号在其他地方登录，如不是本人，请修改密码～", ConstantsCodeStatus.REMOTE_LOGIN_CODE));
    }
}
